package main

import "fmt"
import "sync"
import "time"

var wg sync.WaitGroup

func main() {
	//f("direct")
	//go f("goroutine")
	wg.Add(1)
	go func(msg string) {
		fmt.Println(msg)
		defer wg.Done()
	}("going")

	wg.Wait()
	//var input string
	//fmt.Scanln(&input)
	//fmt.Println("done")

	/*
		wg.Add(3)
		go cook(1)
		go cook(2)
		go cook(3)
		wg.Wait()
	*/

	/*
	   //通道：是用来在协程之间传递数据
	   ch := make(chan int)
	   wg.Add(1)
	   go func(){
	       defer wg.Done()
	       ch <-10
	       ch <-12
	   }()
	   wg.Add(1)

	   go func(){
	       defer wg.Done()
	       r := <-ch
	       fmt.Println("r",r)
	   }()
	   wg.Wait()
	*/
}

func cook(num int) {
	defer wg.Done()
	fmt.Println(fmt.Sprint(num) + "厨师正在工作")
	time.Sleep(time.Second)
	fmt.Println(fmt.Sprint(num) + "厨师已经工作完成")
}

func f(from string) {
	for i := 0; i < 3; i++ {
		fmt.Println(from, ":", i)
	}
}
